Validate config_db.json in reload path.#4521
Conversation
Signed-off-by: dypet <dypeters@cisco.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: dypet <dypeters@cisco.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Hi @qiluo-msft - please help review and merge. |
There was a problem hiding this comment.
Pull request overview
This PR adds YANG validation for the default /etc/sonic/config_db.json during the config reload path to prevent invalid config loads from partially applying and leaving the system in an unrecoverable state (per sonic-buildimage#27178).
Changes:
- Validate the default CONFIG_DB JSON (
DEFAULT_CONFIG_DB_FILE) duringconfig reloadwhen no filename is provided. - Extend unit tests to assert that validation is invoked and that reload aborts early when validation fails.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
config/main.py |
Adds a default-config validation step in the reload path before stopping services / flushing CONFIG_DB. |
tests/config_test.py |
Updates reload tests to assert validation is called; adds a failure-path test to ensure reload aborts before executing commands. |
| if filename is None and file_format == 'config_db': | ||
| # Validate the default config before stopping services and flushing CONFIG_DB. | ||
| config_file_yang_validation(DEFAULT_CONFIG_DB_FILE) | ||
| elif filename is not None and filename != "/dev/stdin": |
| # Validate the default config before stopping services and flushing CONFIG_DB. | ||
| config_file_yang_validation(DEFAULT_CONFIG_DB_FILE) |
There was a problem hiding this comment.
agree that multi-ASIC mode fix is missing. @dypet could you check?
| if filename is None and file_format == 'config_db': | ||
| # Validate the default config before stopping services and flushing CONFIG_DB. | ||
| config_file_yang_validation(DEFAULT_CONFIG_DB_FILE) |
There was a problem hiding this comment.
agree with this finding.
|
A design question: should we skip yang validation if |
Signed-off-by: dypet <dypeters@cisco.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: dypet <dypeters@cisco.com>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Hi @qiluo-msft , please help merge |
|
Hi @qiluo-msft - please help merge. |
What I did
Fix for sonic-net/sonic-buildimage#27178 . /etc/sonic/config_db.json was not validated in the config reload path before loading. If a config that did not conform to schema was partially loaded, the system could end up in a bad unrecoverable state.
How I did it
added a config_file_yang_validation check to config_db.json in config reload path.
How to verify it
'config reload -y' after copying an invalid config to /etc/sonic/config_db.json.
Previous command output
Config is partially loaded in this case, leaving system in state that needs to be recovered with
New command output
The incorrect config is not loaded in this case and system stays up.